<?php

/**
 * Trida entity pro zaznamenavani aktualizace.
 *
 * @author David Dusek
 */
namespace CMS\Updater\Models;

use Doctrine\ORM\Mapping as ORM;

/** 
 * @ORM\Entity(repositoryClass="\CMS\Updater\Models\UpdateRepository")
 * @ORM\Table(name="updater_update")
 */
class Update extends \Nette\Object {    
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     * @var int 
     */
    private $id;
    
    /**
     * @ORM\Column(name="update_date", type="datetime")
     * @var string 
     */
    private $date;
    
    /**
     * @ORM\Column(name="svn_path", length=255)
     * @var string 
     */    
    private $svnPath;
    
    /**
     * @ORM\Column(name="svn_dir", length=255)
     * @var string 
     */    
    private $svnDir;
    
    /**
     * @ORM\Column(type="text")
     * @var string 
     */
    private $modules; 
    
    /**
     * @ORM\ManyToMany(targetEntity="CMS\Updater\Models\Domain")
     * @ORM\JoinTable(name="updater_update_domain",
     *      joinColumns={@ORM\JoinColumn(name="update_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="domain_id", referencedColumnName="id")}
     *      )
     */
    private $domains;
    
    public function __construct()
    {
        $this->domains = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    public function getId() {
        return $this->id;
    }
    
    public function setDate($date) {
        $this->date = $date; 
    }

    public function getDate() {
        return $this->date;
    }

    public function setSvnDir($svnDir) {
        $this->svnDir = $svnDir; 
    }

    public function getSvnDir() {
        return $this->svnDir;
    }

    public function setSvnPath($svnPath) {
        $this->svnPath = $svnPath; 
    }

    public function getSvnPath() {
        return $this->svnPath;
    } 
    
    /**
     * Nastaveni aktualizovanych modulu.
     * @param array $modules 
     */
    public function setModules($modules) {
        $this->modules = implode(',', $modules);
    }

    /**
     * Ziskani seznamu vsech aktualizovanych modulu.
     * @return array 
     */
    public function getModules() {
        return explode(',', $this->modules);
    }
    
    /* Domains */
    public function addDomain(Domain $domain) {
        $this->domains->add($domain);
    }
    
    public function removeDomain(Domain $domain) {
        $this->domains->removeElement($domain);
    }
    
    public function getDomains() {
        return $this->domains;
    }
}
